//Catch That Cow S:https://www.luogu.com.cn/problem/P1588

#include <iostream>
#include <cstring>
#include <queue>

using namespace std;
const int N = 1e5 + 10;

bool m[N]; 
int x,y;
queue<int> q;

int dx[]={-1,1};

int bfs()
{
	int s = 0;
	m[x] = true;
	q.push(x);
	while(q.size())
	{
		s++;
		int k = q.size();
		while(k--)
		{
			x = q.front();
			q.pop();
			for(int i = 0; i < 3; i++)
			{
				int a;
				if(i== 2)
				{
					a = x * 2;
				}
				else
					a = x + dx[i];
				if(a < 0 || a > 1e5 || m[a] == true)continue;
				if(a == y) return s;
				q.push(a);
				m[a] = true;
			}
		}
	}
	return 0;
}

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		memset(m,0,sizeof m);
		queue<int>().swap(q);
		cin >> x >> y;
		cout << bfs() << endl;
	}
	return 0;
}
